package net.pm.core.dateEdtor;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;

import net.pm.common.toolkit.RegexValidUtils;
import net.pm.common.toolkit.StringUtils;
import net.pm.common.toolkit.date.DateUtils;

import org.springframework.stereotype.Component;

/**Date 自定义数据绑定
 */

@Component("DateEditor_Short")
public class DateEditor_Short extends PropertyEditorSupport {
	
	
	@Override
	public String getAsText() {
		return (getValue() == null) ? "" : getValue().toString();
	}

	@Override
	public void setAsText(String text){
		if(StringUtils.isEmpty(text)){
			this.setValue(null);
			return;
		}
		if(!RegexValidUtils.isDateShort(text)){
			return;
		}
		try {
			this.setValue(DateUtils.shortDateFormat.parse(text));
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

}
